<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%--
Created by GaoXiang
Date: 2020-10-10 13:34:00 星期六
Version: 1.0
用户添加页面
--%>

<div class="portlet light">

    <div class="portlet-body form">
        <!-- BEGIN FORM-->
        <form action="#" class="form-horizontal" id="save-module">
            <div class="form-body">

                <div class="row">
                    <div class="col-md-6 hide">
                        <div class="form-group">
                            <label class="control-label col-md-3">ID</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" name="id" value="${longId}" placeholder="默认生成，ID">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">部门</label>
                            <div class="col-md-9">
                                <select class="form-control" required name="orgId">
                                    <option value="" selected>请选择部门</option>
                                    <c:forEach items="${departmentList}" var="item">
                                        <option value="${item.id}">${item.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">人员姓名</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" maxlength="100" required name="name" placeholder="请输入人员姓名">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">人员工号</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" maxlength="50" required name="number" placeholder="请输入人员工号">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">性别</label>
                            <div class="col-md-9">
                                <select  class="form-control" required name="sex" >
                                    <option value="" selected hidden>请选择人员性别</option>
                                    <option value="男">男</option>
                                    <option value="女">女</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">手机号</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="phone" maxlength="20" placeholder="请填写人员手机号">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">职位</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="position" maxlength="20" placeholder="请填写人员职位">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label  col-md-3">头像</label>
                            <div class="col-md-9">
                                <input type="file" required name="file" class="hidden"  id="firstImg"/>
                                <img id="firstImgUrl" src="/static/images/uploadImg.png" onclick="$('#firstImg').click();"  style="width: 120px;height: 120px;"/>
                            </div>
                        </div>
                    </div>


                 <%--   <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">createTime</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="createTime" placeholder="createTime">
                            </div>
                        </div>
                    </div>--%>

            <%--        <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">totalScore</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="totalScore" placeholder="totalScore">
                            </div>
                        </div>
                    </div>--%>
                </div>
            </div>
            <div class="form-actions">
                <div class="row">
                    <div class="col-md-6">
                        <div class="row">
                            <div class="col-md-offset-3 col-md-9">
                                <button type="button" class="btn green" onclick="save();">保存用户</button>
                                <button type="button" class="btn default" onclick="layer.close(layer_addModule);">取消</button>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6"> </div>
                </div>
            </div>
        </form>
        <!-- END FORM-->
    </div>
</div>
<!-- script 开始 -->
<script>

    $(function(){
        //初始化页面
        initPage();
    });

    var firstImg ="";

    $("#firstImg").fileupload({
        url: "/users/headImage",
        dataType: 'json',
        formData: {},
        add: function (e, data) {
            data.submit();
        },
        done: function (e, data) {
            var result = data.result;
            var imgUrl = result.msg;
            if (result.success == false) {
                alert("上传失败");
            } else {
                if(firstImg !=""){
                    $.ajax({
                        url: "/users/delImage",
                        data: {"url": firstImg},
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            $("#firstImgUrl").attr("src","/sysImage/showImg?src="+imgUrl);
                            firstImg =imgUrl;
                        }
                    });
                }else{
                    $("#firstImgUrl").attr("src","/sysImage/showImg?src="+imgUrl);
                    firstImg =imgUrl;
                }

            }
        },
    })

    /**
     * 保存用户
     */
    function save(){
        var param = tools.formParams("save-module");
        param.firstImg=firstImg;
        if(tools.valid("save-module")){
            tools.post("/users/save",param,function(data){
                if(data.success){
                    layer.msg('用户保存成功', {icon: 1,time:1000},function(){
                        //刷新列表页面
                        toPage(null);
                        //关闭弹窗
                        layer.close(layer_addModule);
                    });
                }else{
                    tools.errorTip(data.code,data.msg);
                }
            });
        }
    }

</script>
<!-- script 结束 -->